home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / AACD / Sound / Subspace68k / src / Subspace68k2.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-05-04  |  35.6 KB  |  1,436 lines

  1. #define P96 //SuRgEoN :for compatibility - still through cgfx
  2.  
  3. #ifdef __PPC__
  4. #define MAXWIDTH  640
  5. #define MAXHEIGHT 480
  6. #else
  7. #define MAXWIDTH  512
  8. #define MAXHEIGHT 384
  9. #endif
  10. #define NUMFIELDS 19
  11. #define NUMWAVES 12
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <time.h>
  17. #include <math.h>
  18.  
  19. #include <exec/types.h>
  20. #include <exec/memory.h>
  21. #include <proto/exec.h>
  22. #include <proto/dos.h>
  23. #include <proto/intuition.h>
  24. #include <proto/graphics.h>
  25. #include <proto/cybergraphics.h>
  26. #include <proto/icon.h>
  27. #include <proto/keymap.h>
  28. #include <devices/timer.h>
  29. #include <proto/timer.h>
  30. #include <exec/devices.h>
  31.  
  32. #include <workbench/startup.h>
  33. #include <dos/dostags.h>
  34. #include <graphics/gfxbase.h>
  35. #include <cybergraphx/cybergraphics.h>
  36. #include <libraries/picasso96.h>
  37. #include <clib/picasso96_protos.h>
  38. #ifdef __SASC
  39. struct Library *PPCLibBase;
  40. #include <PowerUP/PPCLib/tasks.h>
  41. ULONG    PPCCallOS(struct Caos*);
  42. ULONG    PPCSetTaskAttrs(void*, struct TagItem*);
  43.  
  44. #define    PPCSetTaskAttrs(TaskObject, Tags)    _PPCSetTaskAttrs(PPC_BASE_NAME, TaskObject, Tags)
  45. static __inline ULONG _PPCSetTaskAttrs(void *PPCLibBase, void*TaskObject, struct TagItem*Tags) {
  46.     struct Caos    MyCaos;
  47.     MyCaos.M68kCacheMode    =    IF_CACHEFLUSHALL;
  48.     MyCaos.PPCCacheMode    =    IF_CACHEFLUSHALL;
  49.     MyCaos.a0        =(ULONG) TaskObject;
  50.     MyCaos.a1        =(ULONG) Tags;
  51.     MyCaos.caos_Un.Offset    =    (-192);
  52.     MyCaos.a6        =(ULONG) PPCLibBase;    
  53.     return((ULONG)PPCCallOS(&MyCaos));
  54. }
  55. #endif
  56.  
  57.  
  58. #include "TrackInfo.h"
  59.  
  60. BOOL PluginInit(int argc, char **argv);
  61. void PluginExit(void);
  62. void PluginLoop(void); //mainloop for viasualization effects
  63. void ShowRequester(char *Text, char *Button);
  64. struct MsgPort *MyCreatePort(UBYTE *name, LONG pri);
  65. void MyDeletePort(struct MsgPort *mp);
  66.  
  67. /***************************************************************************/
  68. /* This is the global variables section. Don't change anything here unless */
  69. /* you know what you're doing!                                             */
  70. /***************************************************************************/
  71.  
  72. BYTE             PluginSignal, InfoSignal, ConfigSignal;
  73. ULONG            PluginMask,   InfoMask,   ConfigMask;
  74. BOOL             Accepted;
  75. struct Process   *PluginTask;
  76. struct MsgPort   *PluginMP;
  77. struct MsgPort   *PluginRP;
  78. struct TrackInfo *tinfo;
  79.  
  80. #ifdef __SASC
  81. struct Library     *TimerBase;
  82. #else
  83.  #ifdef __VBCC__ //SuRgEoN
  84. struct Library      *TimerBase = NULL;
  85.  #else
  86. struct Device      *TimerBase;
  87.  #endif
  88. #endif
  89. struct MsgPort     *TimerMP;
  90. struct timerequest *TimerIO = NULL;
  91. struct EClockVal   ev1;
  92. struct EClockVal   ev2;
  93. BYTE               TimerError = -1;
  94. ULONG              EFreq=0;
  95. ULONG              TimerMask;
  96.  
  97. UWORD    TrackInfoPos = 1;
  98.  
  99. UWORD    *PluginRawL;
  100. UWORD    *PluginRawR;
  101. WORD    *PluginSamples;
  102. UWORD    *SpecRawL;
  103. UWORD    *SpecRawR;
  104. WORD *SampleRaw;
  105.  
  106. struct PluginMessage {
  107.     struct Message   msg;
  108.     ULONG            PluginMask;
  109.     struct Process   *PluginTask;
  110.     UWORD            **SpecRawL;
  111.     UWORD            **SpecRawR;
  112.     UWORD            Accepted;
  113.     UWORD            reserved0;
  114.     ULONG            InfoMask;
  115.     struct TrackInfo **tinfo;
  116.     ULONG            ConfigMask;
  117.     WORD             **SampleRaw;
  118. };
  119.  
  120. BOOL OpenTimer(void);
  121. void CloseTimer(void);
  122. void StartTimer(void);
  123.  
  124. /***************************************************************************/
  125. /* This is the main part. Again, don't change anything here if you haven't */
  126. /* got a very good reason to do so!                                        */
  127. /***************************************************************************/
  128.  
  129. int main(int argc, char **argv) {
  130.     struct PluginMessage *PluginMsg;
  131.     struct PluginMessage *ReplyMsg;
  132.  
  133.  
  134.     /* Allocate all user resources */
  135.     if(PluginInit(argc, argv)) {
  136.         /* Check if a plugin capable instance of AmigaAMP is running */
  137.         if(PluginMP=FindPort("AmigaAMP plugin port"))    {
  138.             /* Allocate some sigbits for receiving signals FROM AmigaAMP */
  139.             PluginSignal = AllocSignal(-1);
  140.             ConfigSignal = AllocSignal(-1);
  141.             InfoSignal   = AllocSignal(-1);
  142.             PluginTask   = (struct Process *)FindTask(NULL);
  143.  
  144.             if(PluginSignal != -1 && InfoSignal != -1 && PluginSignal != -1) {
  145.                 PluginMask = 1L << PluginSignal;
  146.                 ConfigMask = 1L << ConfigSignal;
  147.                 InfoMask   = 1L << InfoSignal;
  148.  
  149.                 /* Allocate a message and reply port for sending messages TO AmigaAMP */
  150.                 #if defined (__SASC) || defined (__VBCC__) //SuRgEoN
  151. #ifdef __PPC__
  152.                 PluginMsg=PPCAllocVec(sizeof(struct PluginMessage), MEMF_PUBLIC|MEMF_CLEAR);
  153. #else
  154.                 PluginMsg=AllocVec(sizeof(struct PluginMessage), MEMF_PUBLIC|MEMF_CLEAR);
  155. #endif
  156.                 PluginRP=(struct MsgPort*)MyCreatePort(0,0);
  157.                 #else
  158.                 PluginMsg=AllocVecPPC(sizeof(struct PluginMessage), MEMF_PUBLIC|MEMF_CLEAR, 0);
  159.  
  160.                 PluginRP=(struct MsgPort*)CreatePort(0,0);
  161.                 #endif
  162.  
  163.                 /* Tell AmigaAMP all the details it needs to know */
  164.                 PluginMsg->msg.mn_Node.ln_Type = NT_MESSAGE;
  165.                 PluginMsg->msg.mn_Length       = sizeof(struct PluginMessage);
  166.                 PluginMsg->msg.mn_ReplyPort    = PluginRP;
  167.                 PluginMsg->PluginMask          = PluginMask;
  168.                 PluginMsg->PluginTask          = PluginTask;
  169.                 PluginMsg->SpecRawL            = &SpecRawL;
  170.                 PluginMsg->SpecRawR            = &SpecRawR;
  171.                 PluginMsg->InfoMask            = InfoMask;
  172.                 PluginMsg->tinfo               = &tinfo;
  173.                 PluginMsg->ConfigMask          = ConfigMask;
  174.                 PluginMsg->SampleRaw           = &SampleRaw;
  175.                 PutMsg(PluginMP, (struct Message *)PluginMsg);
  176.                 /* Wait for a reply */
  177.                 WaitPort(PluginRP);
  178.                 /* Let's see if AmigaAMP accepted our registration attempt */
  179.                 if(ReplyMsg = (struct PluginMessage *)GetMsg(PluginRP)) Accepted=ReplyMsg->Accepted;
  180.                 else Accepted=FALSE;
  181.  
  182.                 if(Accepted) {
  183.                     /* If it did, start the plugin loop */
  184.                     printf("Init ok! - entering plugin loop\n");
  185.                     PluginLoop();
  186.  
  187.                     /* Tell AmigaAMP that this plugin is going down */
  188.                     PluginMsg->PluginMask          = 0;
  189.                     PluginMsg->PluginTask          = NULL;
  190.                     PluginMsg->SpecRawL            = NULL;
  191.                     PluginMsg->SpecRawR            = NULL;
  192.                     PluginMsg->ConfigMask          = 0;
  193.                     PluginMsg->InfoMask            = 0;
  194.                     PluginMsg->tinfo               = NULL;
  195.                     PluginMsg->SampleRaw           = NULL;
  196.                     PutMsg(PluginMP, (struct Message *)PluginMsg);
  197.                     /* Wait for confirmation before going on! */
  198.                     WaitPort(PluginRP);
  199.                     GetMsg(PluginRP);
  200.                     /* Now that AmigaAMP knows that we're gone, we can quit */
  201.                 }
  202.                 else {
  203.                     /* If AmigaAMP didn't accept us, tell the user about it */
  204.                     ShowRequester("Plugin rejected by AmigaAMP!\nPerhaps there's another one running.", "Abort");
  205.                 }
  206.  
  207.                 /* Free all resources */
  208.                 #ifdef __SASC
  209.  
  210.                     PPCFreeVec(PluginMsg);
  211.                     MyDeletePort(PluginRP);
  212.                 #else
  213.                     #ifndef PPC__ //SuRgEoN
  214.                     FreeVec(PluginMsg);
  215.                     DeletePort(PluginRP);
  216.                     #else
  217.                     FreeVecPPC(PluginMsg);
  218.                     DeletePort(PluginRP);
  219.                     #endif
  220.                 #endif
  221.             }
  222.             else {
  223.                 ShowRequester("Signal allocation failure!", "Abort");
  224.             }
  225.             if(PluginSignal != -1) FreeSignal(PluginSignal);
  226.             if(ConfigSignal != -1) FreeSignal(ConfigSignal);
  227.             if(InfoSignal   != -1) FreeSignal(InfoSignal);
  228.         }
  229.         else {
  230.             ShowRequester("Could not find message port!\nAmigaAMP probably not running.", "Abort");
  231.         }
  232.     }
  233.     else {
  234.         ShowRequester("Plugin initialisation failed!", "Ok");
  235.     }
  236.     /* Free all user resources */
  237.     PluginExit();
  238. }
  239.  
  240. /*****************************************************************************/
  241. /* Ok, now for the individual plugin sourcecode. Everything below should be  */
  242. /* changed to your needs.                                                    */
  243. /* Just like before, we start with the global variables section              */
  244. /*****************************************************************************/
  245.  
  246. void InitWave(UBYTE WaveNum, ULONG BufNum);
  247. void CalcWave(UBYTE WaveNum, ULONG BufNum);
  248. void DrawWave(LONG *WaveX, LONG *WaveY, ULONG Width, ULONG Height, UBYTE WaveNum, ULONG BufNum);
  249.  
  250. void InitField(LONG *Zoom, ULONG Width, ULONG Height);
  251. void PrepareConstants(UBYTE FieldNum);
  252. void CalcLine(LONG *Zoom, ULONG Width, ULONG Height, UBYTE FieldNum);
  253. void MakeCMap(void);
  254. void Blur(UBYTE *PixelC, UBYTE *PixelD);
  255. void ReColor(void);
  256. void MakeTitle(void);
  257. float rnd(float max);
  258. float sgn(float val);
  259.  
  260. const char VersionString[]="\0$VER: Subspace 1.1 (10.11.00)";
  261. const char Line1[]="Subspace";
  262. const char Line2[]="by Thomas Wenzel";
  263.  
  264. #define PRECISION PRECISION_EXACT
  265.  
  266. struct IntuitionBase *IntuitionBase = NULL;
  267. struct GfxBase *GfxBase      = NULL;
  268. struct Library *IconBase     = NULL;
  269. struct Library *KeymapBase   = NULL;
  270. struct Library *AslBase      = NULL;
  271. struct Library *GadToolsBase = NULL;
  272. struct Library *CyberGfxBase = NULL;
  273. struct Library *P96Base = NULL;
  274. struct Screen  *PluginScreen = NULL;
  275. struct Window  *PluginWin    = NULL;
  276. struct RastPort *rp;
  277. struct ViewPort *vp;
  278.  
  279.  
  280. struct EClockVal ev1;
  281. struct EClockVal ev2;
  282.  
  283.  
  284. ULONG ModeID;
  285. ULONG WinMask;
  286.  
  287. UBYTE *PixelD;
  288. UBYTE *PixelC;
  289. ULONG *Colour;
  290.  
  291. UWORD *EmptyPointer;
  292.  
  293. char InfoLine[256];
  294.  
  295. LONG Zoom[MAXWIDTH*MAXHEIGHT];
  296. LONG Zoom2[MAXWIDTH*MAXHEIGHT];
  297. LONG WaveX[MAXWIDTH*2];
  298. LONG WaveY[MAXWIDTH*2];
  299. LONG WaveX2[MAXWIDTH*2];
  300. LONG WaveY2[MAXWIDTH*2];
  301.  
  302. ULONG MidR[4], MidG[4], MidB[4];
  303. ULONG DisplayFPS;
  304. ULONG ShowWave;
  305. ULONG LimitFPS;
  306. #ifdef __PPC__
  307. ULONG ScreenSize = 100;
  308. #else
  309. ULONG ScreenSize = 60;
  310. #endif
  311. #ifdef PPC
  312. ULONG Width      = 320;
  313. ULONG Height     = 240;
  314. ULONG HalfHeight = 120;
  315. #else
  316. ULONG Width      = 256; //256*192
  317. ULONG Height     = 170; //120 with ScreenSize 80!
  318. ULONG HalfHeight = 70;
  319. #endif
  320. #ifndef __PPC__
  321. ULONG Woffset     = 32; //32 for width 256
  322. #else
  323. ULONG Woffset     = 0;
  324. #endif
  325.  
  326. ULONG Cutoff     = 1;
  327. ULONG InfoCount;
  328. ULONG FrameCountLow;
  329. ULONG FrameCountHigh;
  330. ULONG FrameCountWave;
  331. ULONG FrameCountField;
  332. ULONG TimeWave;
  333. ULONG DestWaveNum;
  334. ULONG DestWaveBuffer;
  335. float WaveMorph;
  336. ULONG MidRdst[3], MidGdst[3], MidBdst[3];
  337. ULONG LineToCalc;
  338. UBYTE FieldToCalc;
  339. UBYTE WaveToCalc, WaveToCalc0, WaveToCalc1;
  340. UBYTE PrevField;
  341.  
  342. /****************************************************************************/
  343. /* This function will be called once when the plugin is started. You should */
  344. /* allocate all needed resources here. Return TRUE if all went well.        */
  345. /****************************************************************************/
  346.  
  347. BOOL PluginInit(int argc, char **argv) {
  348.     long i,xs,ys,xd,yd,ysp,ydp;
  349.     float xf,yf;
  350.     UBYTE **ttypes = 0; //VBCC
  351.     char *str;
  352.     struct DiskObject *IconObj = NULL; //VBCC
  353.     struct WBStartup  *WBStart = NULL; //VBCC
  354.     #ifdef __SASC
  355.     void *ThisTask;
  356.     #else
  357.     struct TaskPPC *ThisTask;
  358.     #endif
  359.     WORD Length;
  360.  
  361. #ifdef __PPC__
  362.     struct TagItem ModeIDtags[] = {
  363.         CYBRBIDTG_Depth, 8, CYBRBIDTG_NominalWidth, 320, CYBRBIDTG_NominalHeight, 240, TAG_DONE
  364.     };
  365. #else
  366.     struct TagItem ModeIDtags[] = {
  367.         CYBRBIDTG_Depth, 8, CYBRBIDTG_NominalWidth, 320, CYBRBIDTG_NominalHeight, 200, TAG_DONE};
  368. #endif
  369.     AslBase=OpenLibrary("asl.library", 0);
  370.     if(!AslBase) {
  371.         ShowRequester("Can't open asl.library!", "Abort");
  372.         return(FALSE);
  373.     }
  374.  
  375.     IconBase=OpenLibrary("icon.library", 0);
  376.     if(!IconBase) {
  377.         ShowRequester("Can't open icon.library!", "Abort");
  378.         return(FALSE);
  379.     }
  380.  
  381.     KeymapBase=OpenLibrary("keymap.library", 0);
  382.     if(!KeymapBase) {
  383.         ShowRequester("Can't open keymap.library!", "Abort");
  384.         return(FALSE);
  385.     }
  386.  
  387.     IntuitionBase=(struct IntuitionBase*)OpenLibrary("intuition.library", 0);
  388.     if(!IntuitionBase) {
  389.         ShowRequester("Can't open intuition.library!", "Abort");
  390.         return(FALSE);
  391.     }
  392.  
  393.     GadToolsBase=OpenLibrary("gadtools.library", 0);
  394.     if(!GadToolsBase) {
  395.         ShowRequester("Can't open gadtools.library!", "Abort");
  396.         return(FALSE);
  397.     }
  398.  
  399.     GfxBase=(struct GfxBase*)OpenLibrary("graphics.library", 0);
  400.     if(!GfxBase) {
  401.         ShowRequester("Can't open graphics.library!", "Abort");
  402.         return(FALSE);
  403.     }
  404.  
  405.     if(GfxBase->LibNode.lib_Version < 39) {
  406.         ShowRequester("This plugin requires AmigaOS 3.0 or greater!", "Abort");
  407.         return(FALSE);
  408.     }
  409.     CyberGfxBase=OpenLibrary("cybergraphics.library", 40);
  410.     if(!CyberGfxBase) {
  411.         ShowRequester("This plugin requires CyberGraphX v3 or higher!", "Abort");
  412.         return(FALSE);
  413.     }
  414.       P96Base = OpenLibrary("Picasso96API.library",0);
  415.     if(!P96Base) {
  416.         ShowRequester("This plugin requires Picasso96", "Abort");
  417.         return(FALSE);
  418.     }
  419.     #ifdef __SASC
  420.         /* Increase the priority of the 68k mirror task */
  421.         SetTaskPri(FindTask(NULL), 15);
  422.         /* Increase our own priority (if it only would work...) */
  423.         PPCSetTaskAttr(PPCTASKTAG_PRIORITY, 15);
  424.     #else
  425.         #ifdef __VBCC__
  426.     //        SetTaskPri(FindTask(NULL), 15);
  427.         #else
  428.         /* Increase our own priority */
  429.         ThisTask = FindTaskPPC(NULL);
  430.         SetNiceValue(ThisTask, -15);
  431.         #endif
  432.     #endif
  433.  
  434.     WBStart=(struct WBStartup *)argv;
  435.  
  436. // if(argc==0) printf("IconName: %s\n", WBStart->sm_ArgList[0].wa_Name);
  437.  
  438.     if(argc==0) IconObj=GetDiskObject(WBStart->sm_ArgList[0].wa_Name);
  439.     else        IconObj=GetDiskObject(argv[0]);
  440.  
  441.     LimitFPS = 999;
  442.  
  443.     if(IconObj) {
  444.         if(str=FindToolType(IconObj->do_ToolTypes,"MAXFPS"))
  445.         {
  446.             LimitFPS = atol(str);
  447.         }
  448.  
  449.         if(str=FindToolType(IconObj->do_ToolTypes,"RESOLUTION"))
  450.         {
  451.             if(stricmp(str,"high") == 0) {
  452.                 Width      = 640;
  453.                 Height     = 480;
  454.                 ScreenSize = 66;
  455.             }
  456.             else {
  457. #ifdef __PPC__
  458.                 Width      = 320;
  459.                 Height     = 240;
  460.                 ScreenSize = 100;
  461. #else
  462.                 Width      = 256;
  463.                 Height       = 170;
  464.                 ScreenSize = 60;
  465. #endif
  466.  
  467.             }
  468.         }
  469.  
  470.         if(str=FindToolType(IconObj->do_ToolTypes,"SCREENSIZE"))
  471.         {
  472.             ScreenSize = atol(str);
  473.         }
  474.     FreeDiskObject(IconObj);
  475.     }
  476.  
  477.     if(ttypes=(UBYTE**)ArgArrayInit(argc, argv)) {
  478.         str=(char*)ArgString(ttypes, "MAXFPS", "0");
  479.         LimitFPS = atol(str);
  480.  
  481.         str=(char*)ArgString(ttypes, "RESOLUTION", "low");
  482.         if(stricmp(str,"high") == 0) {
  483.             Width      = 640;
  484.             Height     = 480;
  485.             ScreenSize = 66;
  486.             ShowWave   = 1;
  487.         }
  488.         else {
  489. #ifdef __PPC__
  490.             Width      = 320;
  491.             Height     = 240;
  492.             ScreenSize = 100;
  493. #else
  494.             Width      = 256; //240
  495.             Height       = 170; //190
  496.             ScreenSize = 60; //60
  497. #endif
  498.             ShowWave   = 0;
  499.         }
  500.  
  501.         if(str=(char*)ArgString(ttypes, "SCREENSIZE", NULL)) {
  502.             ScreenSize = atol(str);
  503.         }
  504.  
  505.         ArgArrayDone();
  506.     }
  507.  
  508.     if(LimitFPS == 0)  LimitFPS = 999;
  509.     if(LimitFPS > 999) LimitFPS = 999;
  510.  
  511.     if(ScreenSize <  25) ScreenSize =  25;
  512.     if(ScreenSize > 100) ScreenSize = 100;
  513.  
  514.     Cutoff = Height * (100-ScreenSize) / 200;
  515.     if(Cutoff <   1) Cutoff =   1;
  516.     if(Cutoff > 200) Cutoff = 200;
  517.  
  518.     ModeIDtags[1].ti_Data = Width;
  519.     ModeIDtags[2].ti_Data = Height;
  520.  
  521.     HalfHeight = Height/2;
  522.  
  523.     #if defined (__SASC) || defined (__VBCC__)
  524.         #ifdef __PPC__
  525.         PixelD       = PPCAllocVec(Width*Height, MEMF_PUBLIC|MEMF_CLEAR);
  526.         PixelC       = PPCAllocVec(Width*Height, MEMF_PUBLIC|MEMF_CLEAR);
  527.         Colour       = PPCAllocVec(770*4,        MEMF_PUBLIC|MEMF_CLEAR);
  528.         EmptyPointer = PPCAllocVec(512,          MEMF_CHIP|MEMF_CLEAR);
  529.         #else //68k
  530.         PixelD       = AllocVec(Width*Height, MEMF_PUBLIC|MEMF_CLEAR);
  531.         PixelC       = AllocVec(Width*Height, MEMF_PUBLIC|MEMF_CLEAR);
  532.         Colour       = AllocVec(770*4,        MEMF_PUBLIC|MEMF_CLEAR);
  533.         EmptyPointer = AllocVec(512,          MEMF_CHIP|MEMF_CLEAR);
  534.         #endif
  535.     #else
  536.         PixelD       = AllocVecPPC(Width*Height, MEMF_PUBLIC|MEMF_CLEAR, 0);
  537.         PixelC       = AllocVecPPC(Width*Height, MEMF_PUBLIC|MEMF_CLEAR, 0);
  538.         Colour       = AllocVecPPC(770*4,        MEMF_PUBLIC|MEMF_CLEAR, 0);
  539.         EmptyPointer = AllocVecPPC(512,          MEMF_CHIP|MEMF_CLEAR,   0);
  540.     #endif
  541.  
  542.     OpenTimer();
  543.  
  544.     if(PixelD==NULL || PixelC==NULL) {
  545.         ShowRequester("Out of memory for graphics buffers!", "Abort");
  546.         return(FALSE);
  547.     }
  548.  
  549.     srand(time(NULL));
  550.  
  551.     MidR[0] = 230;
  552.     MidG[0] = 230;
  553.     MidB[0] = 230;
  554.  
  555.     MidR[1] = 86;
  556.     MidG[1] = 86;
  557.     MidB[1] = 170;
  558.  
  559.     MidR[2] = 25;
  560.     MidG[2] = 25;
  561.     MidB[2] = 100;
  562.  
  563.     MidR[3] = 0;
  564.     MidG[3] = 0;
  565.     MidB[3] = 0;
  566.  
  567.     MidRdst[0] = (UBYTE)(rand()>>25) + 127;
  568.     MidGdst[0] = (UBYTE)(rand()>>25) + 127;
  569.     MidBdst[0] = (UBYTE)(rand()>>25) + 127;
  570.  
  571.     MidRdst[1] = (UBYTE)(rand()>>25) + 96;
  572.     MidGdst[1] = (UBYTE)(rand()>>25) + 96;
  573.     MidBdst[1] = (UBYTE)(rand()>>25) + 96;
  574.  
  575.     MidRdst[2] = (UBYTE)(rand()>>25) + 64;
  576.     MidGdst[2] = (UBYTE)(rand()>>25) + 64;
  577.     MidBdst[2] = (UBYTE)(rand()>>25) + 64;
  578.  
  579.     DisplayFPS      = 0;
  580.     InfoCount       = 0;
  581.     FrameCountLow   = 0;
  582.     FrameCountHigh  = 0;
  583.     FrameCountWave  = 0;
  584.     FrameCountField = 0;
  585.     TimeWave        = 0;
  586.     DestWaveNum     = 1;
  587.     DestWaveBuffer  = 1;
  588.     WaveMorph       = 0.0;
  589.     LineToCalc      = 0;
  590.     WaveToCalc      = 0;
  591.     WaveToCalc0     = 0;
  592.  
  593. //    FieldToCalc     = (UBYTE)(rand()>>24) % NUMFIELDS);
  594. //    WaveToCalc1     = (UBYTE)(rand()>>24) % NUMWAVES);
  595.  
  596.     FieldToCalc   = 0; //10=endblur;16=radial;2=tunnel
  597.      WaveToCalc1   = 1;
  598. //1=tunnel;2=lines;3=radar;4=flower;5=solsweep;6=xx;7=chaoticlines;8=circwaves;9=occludinglines;10=quad;11=;
  599. //    FieldToCalc   = NUMFIELDS-1;
  600. //    WaveToCalc1   = NUMWAVES-1;
  601.  
  602.  
  603.     PrepareConstants(FieldToCalc);
  604.  
  605.     MakeCMap();
  606. #ifdef P96
  607. //    ModeID=CModeRequestTagList(NULL, ModeIDtags);
  608.     ModeID=p96RequestModeIDTagList(ModeIDtags);
  609. #else
  610.     ModeID=BestCModeIDTagList(NULL, ModeIDtags);
  611. #endif
  612.     if(ModeID == INVALID_ID) {
  613.         ShowRequester("Could not find suitable screen mode!", "Abort");
  614.         return(FALSE);
  615.     }
  616.     
  617.  
  618.     PluginScreen=OpenScreenTags(NULL, SA_DisplayID, ModeID, SA_Depth, 8, SA_Width, Width, SA_Height, Height, SA_SharePens, TRUE, SA_ShowTitle, FALSE, SA_Quiet, TRUE, TAG_DONE);
  619.     if(PluginScreen == NULL) {
  620.         ShowRequester("Could not open screen!", "Abort");
  621.         return(FALSE);
  622.     }
  623.     rp = &PluginScreen->RastPort;
  624.     vp = &PluginScreen->ViewPort;
  625.  
  626.     LoadRGB32(vp, Colour);
  627.  
  628.     PluginWin=OpenWindowTags(NULL, WA_CustomScreen, (ULONG)PluginScreen,
  629.                                    WA_Left,         0,
  630.                                    WA_Top,          0,
  631.                                    WA_Width,        Width,
  632.                                    WA_Height,       Height,
  633.                                    WA_SizeGadget,   FALSE,
  634.                                    WA_DragBar,      FALSE,
  635.                                    WA_DepthGadget,  FALSE,
  636.                                    WA_CloseGadget,  FALSE,
  637.                                    WA_Backdrop,     TRUE,
  638.                                    WA_Borderless,   TRUE,
  639.                                    WA_Activate,     TRUE,
  640.                                    WA_AutoAdjust,   TRUE,  // Just to be sure :-)
  641.                                    WA_IDCMP,        IDCMP_RAWKEY | IDCMP_ACTIVEWINDOW | IDCMP_INACTIVEWINDOW,
  642.                                    TAG_DONE);
  643.     if(PluginWin == NULL) {
  644.         ShowRequester("Could not open window!", "Abort");
  645.         return(FALSE);
  646.     }
  647.  
  648.     SetPointer(PluginWin, EmptyPointer, 1, 1, 0, 0);
  649.     SetAPen(rp, 1);
  650.     RectFill(rp, 0, 0, (Width-1), (Height-1));
  651.     SetAPen(rp, 255);
  652.  
  653.     WinMask = 1L << PluginWin->UserPort->mp_SigBit;
  654.  
  655.     InitField(Zoom, Width, Height);
  656.     MakeTitle();
  657.  
  658.     return(TRUE);
  659. }
  660.  
  661. /******************************************************************************/
  662. /* This function will be called when the plugin is shut down. You should free */
  663. /* all previously allocated resources here.                                   */
  664. /******************************************************************************/
  665.  
  666. void PluginExit(void) {
  667.     long i;
  668.  
  669.     if(PluginWin)    CloseWindow(PluginWin);
  670.     if(PluginScreen) CloseScreen(PluginScreen);
  671.     #ifdef __SASC
  672.         if(PixelD)       PPCFreeVec(PixelD);
  673.         if(PixelC)       PPCFreeVec(PixelC);
  674.         if(Colour)       PPCFreeVec(Colour);
  675.         if(EmptyPointer) PPCFreeVec(EmptyPointer);
  676.     #else
  677.      #ifdef __PPC__    
  678.         if(PixelD)       FreeVecPPC(PixelD);
  679.         if(PixelC)       FreeVecPPC(PixelC);
  680.         if(Colour)       FreeVecPPC(Colour);
  681.         if(EmptyPointer) FreeVecPPC(EmptyPointer);
  682.      #else
  683.         if(PixelD)       FreeVec(PixelD);
  684.         if(PixelC)       FreeVec(PixelC);
  685.         if(Colour)       FreeVec(Colour);
  686.         if(EmptyPointer) FreeVec(EmptyPointer);
  687.      #endif
  688.     #endif
  689.  
  690.     CloseTimer();
  691.     if(CyberGfxBase)  CloseLibrary(CyberGfxBase);
  692.     if(P96Base)  CloseLibrary(P96Base);
  693. //    if(GfxBase)       CloseLibrary(GfxBase);
  694.     if(AslBase)       CloseLibrary(AslBase);
  695.     if(IconBase)      CloseLibrary(IconBase);
  696.     if(KeymapBase)    CloseLibrary(KeymapBase);
  697.     if(GadToolsBase)  CloseLibrary(GadToolsBase);
  698. //    if(IntuitionBase) CloseLibrary(IntuitionBase);
  699. }
  700.  
  701. /*******************************************************************************/
  702. /* This is the main Plugin Loop. It will receive a signal matching PluginMask  */
  703. /* each time new spectral data is ready. The data is stored in two arrays,     */
  704. /* UWORD Spec[512] in structures DataL and DataR. The scale is logarithmic,    */
  705. /* 0 means below -96dB, 65535 means 0dB.                                       */
  706. /* No matter how long it takes until your plugin actually processes the data,  */
  707. /* the memory referenced by the array pointers always remains valid!           */
  708. /*                                                                             */
  709. /* Your plugin loop MUST quit when it receives SIGBREAKF_CTRL_C. If you've     */
  710. /* opened a window you should react to the close gadget as well. For full      */
  711. /* screen plugins I strongly recommend checking the ESC key.                   */
  712. /*******************************************************************************/
  713.  
  714. void PluginLoop(void) {
  715.     struct TextExtent te;
  716.     ULONG *PixelL = 0;
  717.     UBYTE *ActPixel;
  718.     ULONG Signals = 0;
  719.     LONG i,j,k;
  720.     LONG l,r;
  721.     LONG x,y;
  722.     UBYTE v;
  723.     UWORD w;
  724.     UBYTE ColorMode;
  725.  
  726.     ULONG    hi,lo,itime,eclock;
  727.     char FPStext[64];
  728.  
  729.     UBYTE Vanilla;
  730.     struct InputEvent ie;
  731.     WORD    RawLen;
  732.     printf("entering main loop\n");
  733.     Wait(SIGBREAKF_CTRL_C | PluginMask);
  734.  
  735.     /* Make a backup of the data pointers */
  736.     PluginRawL    = SpecRawL;
  737.     PluginRawR    = SpecRawR;
  738.     PluginSamples = SampleRaw;
  739.     WritePixelArray(PixelC, 0, 0, Width, rp, Woffset, 0, Width, Height, RECTFMT_LUT8);
  740.     Delay(100);
  741.  
  742.     StartTimer();
  743.  
  744.     InitWave(WaveToCalc0, 0);
  745.     InitWave(WaveToCalc1, 1);
  746.  
  747.     for(;;) {
  748.         /* Wait until there's something to do */
  749.  
  750.         Signals=Wait(SIGBREAKF_CTRL_C | PluginMask | ConfigMask | InfoMask | WinMask | TimerMask);
  751.         if(Signals & TimerMask) {
  752.             WaitIO((struct IORequest *) TimerIO);
  753.         }
  754.  
  755.         /* Break received -> quit at once! */
  756.         if(Signals & SIGBREAKF_CTRL_C) break;
  757.  
  758.         /* Window close gadget hit -> quit as well! */
  759.         if(Signals & WinMask) {
  760.             struct IntuiMessage *imsg;
  761.             BOOL done=0;
  762.  
  763.             while(imsg=(struct IntuiMessage *)GetMsg(PluginWin->UserPort)) {
  764.                 if(imsg->Class == IDCMP_RAWKEY) {
  765.                     ie.ie_Class        = IECLASS_RAWKEY;
  766.                     ie.ie_SubClass     = 0;
  767.                     ie.ie_Code         = imsg->Code;
  768.                     ie.ie_Qualifier    = 0;
  769.                     ie.ie_EventAddress = imsg->IAddress;
  770.                     RawLen = MapRawKey(&ie, &Vanilla, 1, 0);
  771.  
  772.                     switch(imsg->Code) {
  773.                         case 0x45: done=1; break;
  774.                     }
  775.  
  776.                     if(RawLen==1) {
  777.                         switch(Vanilla) {
  778.                             case 'f': DisplayFPS = 1-DisplayFPS; break;
  779.                             case 'w': ShowWave   = 1-ShowWave;   break;
  780.                             case 'i': InfoCount  = 0;            break;
  781. //                        case '+': Cutoff--;                  break;
  782. //                        case '-': Cutoff++;                  break;
  783.                         }
  784.                         if(Cutoff < 1) Cutoff =   1;
  785.                         if(Cutoff > HalfHeight-10) Cutoff = HalfHeight-10;
  786.                         for(i=0; i<Width*Cutoff; i++) {
  787.                             PixelC[i]=PixelD[i]=0;
  788.                         }
  789.                         for(i=Width*(Height-Cutoff); i<Width*Height; i++) {
  790.                             PixelC[i]=PixelD[i]=0;
  791.                         }
  792.                     }
  793.                 }
  794.                 ReplyMsg(imsg);
  795.             }
  796.             if(done) break;
  797.         }
  798.  
  799.         if(Signals & TimerMask) {
  800.             StartTimer();
  801. //printf("timer started\n");
  802.       Blur(PixelC, PixelD);
  803.  
  804.             FrameCountLow++;
  805.             if(FrameCountLow > 4) {
  806.                 FrameCountLow = 0;
  807.                 eclock=ReadEClock(&ev2);
  808.                 hi = ev2.ev_hi - ev1.ev_hi;
  809.                 lo = ev2.ev_lo - ev1.ev_lo;
  810.                 itime = hi*eclock+lo;
  811.  
  812.                 if(itime==0) itime=1;
  813.  
  814.                 ev1.ev_hi = ev2.ev_hi;
  815.                 ev1.ev_lo = ev2.ev_lo;
  816.                 ReColor();
  817.             }
  818.  
  819.             FrameCountHigh++;
  820.         if(FrameCountHigh > 600) {
  821.                 FrameCountHigh = 0;
  822. #ifndef __VBCC__
  823.                 ColorMode = (UBYTE)(rand()>>24) % 10;
  824.  
  825. #else
  826. /*
  827. if(ColorMode==0)
  828. {
  829.     MidR[0] = 255;
  830.     MidG[0] = 220;
  831.     MidB[0] = 200;
  832.  
  833.     MidR[1] = 170;
  834.     MidG[1] = 96;
  835.     MidB[1] = 170;
  836.  
  837.     MidR[2] = 10;
  838.     MidG[2] = 100;
  839.     MidB[2] = 52;
  840.  
  841. ColorMode=1;
  842. }
  843. */
  844. /*
  845. if(ColorMode==0)
  846. {
  847.     MidR[0] = 255;
  848.     MidG[0] = 200;
  849.     MidB[0] = 255;
  850.  
  851.     MidR[1] = 96;
  852.     MidG[1] = 76;
  853.     MidB[1] = 178;
  854.  
  855.     MidR[2] = 100;
  856.     MidG[2] = 55;
  857.     MidB[2] = 65;
  858.  
  859. ColorMode=1;
  860. }
  861. */
  862.  
  863. if(ColorMode == 0)
  864. {
  865. //blue
  866.     MidR[0] = 230;
  867.     MidG[0] = 230;
  868.     MidB[0] = 230;
  869.  
  870.     MidR[1] = 86;
  871.     MidG[1] = 86;
  872.     MidB[1] = 170;
  873.  
  874.     MidR[2] = 25;
  875.     MidG[2] = 25;
  876.     MidB[2] = 100;
  877.  
  878. ColorMode = 1;
  879. }
  880. else
  881. {
  882. //fire
  883.     MidR[0] = 255;
  884.     MidG[0] = 255;
  885.     MidB[0] = 100;
  886.  
  887.     MidR[1] = 200;
  888.     MidG[1] = 120;
  889.     MidB[1] = 10;
  890.  
  891.     MidR[2] = 100;
  892.     MidG[2] = 25;
  893.     MidB[2] = 25;
  894.  
  895.     MidR[3] = 0;
  896.     MidG[3] = 0;
  897.     MidB[3] = 0;
  898.  
  899. ColorMode = 0;
  900. }
  901.  
  902. #endif
  903.             printf("ColorMode: %d\n", ColorMode);
  904. #ifndef __VBCC__
  905.                 switch(ColorMode) {
  906.                     case 0:
  907.                     case 1:
  908.                         MidRdst[0] = (UBYTE)(rand()>>25) + 127;
  909.                         MidGdst[0] = (UBYTE)(rand()>>25) + 127;
  910.                         MidBdst[0] = (UBYTE)(rand()>>25) + 127;
  911.  
  912.                         MidRdst[1] = (UBYTE)(rand()>>24) + 0;
  913.                         MidGdst[1] = (UBYTE)(rand()>>24) + 0;
  914.                         MidBdst[1] = (UBYTE)(rand()>>24) + 0;
  915.  
  916.                         MidRdst[2] = (UBYTE)(rand()>>24) + 0;
  917.                         MidGdst[2] = (UBYTE)(rand()>>24) + 0;
  918.                         MidBdst[2] = (UBYTE)(rand()>>24) + 0;
  919.                     break;
  920.  
  921.                     case 2:
  922.                         MidRdst[0] = (UBYTE)(rand()>>24) + 0;
  923.                         MidGdst[0] = (UBYTE)(rand()>>24) + 0;
  924.                         MidBdst[0] = (UBYTE)(rand()>>24) + 0;
  925.  
  926.                         MidRdst[1] = (UBYTE)(rand()>>24) + 0;
  927.                         MidGdst[1] = (UBYTE)(rand()>>24) + 0;
  928.                         MidBdst[1] = (UBYTE)(rand()>>24) + 0;
  929.  
  930.                         MidRdst[2] = (UBYTE)(rand()>>24) + 0;
  931.                         MidGdst[2] = (UBYTE)(rand()>>24) + 0;
  932.                         MidBdst[2] = (UBYTE)(rand()>>24) + 0;
  933.                     break;
  934.  
  935.                     case 3:
  936.                         MidRdst[0] = (UBYTE)(rand()>>25) + 0;
  937.                         MidGdst[0] = (UBYTE)(rand()>>25) + 0;
  938.                         MidBdst[0] = (UBYTE)(rand()>>25) + 0;
  939.  
  940.                         MidRdst[1] = (UBYTE)(rand()>>24) + 0;
  941.                         MidGdst[1] = (UBYTE)(rand()>>24) + 0;
  942.                         MidBdst[1] = (UBYTE)(rand()>>24) + 0;
  943.  
  944.                         MidRdst[2] = (UBYTE)(rand()>>24) + 0;
  945.                         MidGdst[2] = (UBYTE)(rand()>>24) + 0;
  946.                         MidBdst[2] = (UBYTE)(rand()>>24) + 0;
  947.                     break;
  948.  
  949.                     default:
  950.                         MidRdst[0] = (UBYTE)(rand()>>25) + 127;
  951.                         MidGdst[0] = (UBYTE)(rand()>>25) + 127;
  952.                         MidBdst[0] = (UBYTE)(rand()>>25) + 127;
  953.  
  954.                         MidRdst[1] = (UBYTE)(rand()>>25) + 64;
  955.                         MidGdst[1] = (UBYTE)(rand()>>25) + 64;
  956.                         MidBdst[1] = (UBYTE)(rand()>>25) + 64;
  957.  
  958.                         MidRdst[2] = (UBYTE)(rand()>>25) + 32;
  959.                         MidGdst[2] = (UBYTE)(rand()>>25) + 32;
  960.                         MidBdst[2] = (UBYTE)(rand()>>25) + 32;
  961.                     break;
  962.                 }
  963. #endif
  964.             }
  965.  
  966.             CalcLine(Zoom2, Width, Height, FieldToCalc);
  967.             LineToCalc++;
  968.             if(LineToCalc > Height-1) LineToCalc = Height-1;
  969.             FrameCountField++;
  970.             
  971.             if(FrameCountField > 500) {
  972.  
  973.             printf("FCF 500\n");
  974.                 FrameCountField=0;
  975.  
  976.                 LineToCalc = 1;
  977.                 PrevField = FieldToCalc;
  978.  
  979. #ifdef __VBCC__
  980.                 if(FieldToCalc == 0)
  981.                 FieldToCalc = 1;
  982.                 else if(FieldToCalc == 1)
  983.                 FieldToCalc = 2;
  984.                 else if(FieldToCalc == 2)
  985.                 FieldToCalc = 3;
  986.                 else if(FieldToCalc == 3)
  987.                 FieldToCalc = 4;
  988.                 else if(FieldToCalc == 4)
  989.                 FieldToCalc = 6;
  990.                 else if(FieldToCalc == 6)
  991.                 FieldToCalc = 7;
  992.                 else if(FieldToCalc == 7)
  993.                 FieldToCalc = 9;
  994.                 else if(FieldToCalc == 9)
  995.                 FieldToCalc = 10;
  996.                 else if(FieldToCalc == 10)
  997.                 FieldToCalc = 13;
  998.                 else if(FieldToCalc == 13)
  999.                 FieldToCalc = 14;
  1000.                 else if(FieldToCalc == 14)
  1001.                 FieldToCalc = 15;
  1002.                 else if(FieldToCalc == 15)
  1003.                 FieldToCalc = 16;
  1004.                 else if(FieldToCalc == 16)
  1005.                 FieldToCalc = 18;
  1006.                 else
  1007.                 FieldToCalc = 0;
  1008. #endif
  1009.  
  1010. #ifndef __VBCC__
  1011.                 do {
  1012.             FieldToCalc=(UBYTE)(rand()>>24) % NUMFIELDS;
  1013.                 } while (FieldToCalc == PrevField);
  1014. #endif
  1015.  
  1016.                 for(j=0; j<Width*Height; j++)
  1017.                 {
  1018.                     Zoom[j]=Zoom2[j];
  1019.                 }
  1020.                 printf("preparing field %d\n", FieldToCalc);
  1021.                 PrepareConstants(FieldToCalc);
  1022.  
  1023.             }
  1024.  
  1025.             for(i=Width*Cutoff; i<Width*(Height-Cutoff); i++) {
  1026.                 PixelC[i]=PixelD[Zoom[i]];
  1027.             }
  1028.  
  1029.  
  1030.             /* Make a backup of the data pointers */
  1031.             PluginRawL    = SpecRawL;
  1032.             PluginRawR    = SpecRawR;
  1033.             PluginSamples = SampleRaw;
  1034.  
  1035.             InfoCount++;
  1036.             if(InfoCount < 75) MakeTitle();
  1037.             else InfoCount=75;
  1038.  
  1039.             TimeWave++;
  1040.             FrameCountWave++;
  1041.             CalcWave(WaveToCalc0, 0);
  1042.             DrawWave(WaveX,  WaveY,  Width, Height, WaveToCalc0, 0);
  1043.             CalcWave(WaveToCalc1, 1);
  1044.             DrawWave(WaveX2, WaveY2, Width, Height, WaveToCalc1, 1);
  1045.             if(FrameCountWave > 200) {
  1046.  
  1047.                 if(DestWaveBuffer == 1) WaveMorph += 0.015; //was 0.005
  1048.                 else                    WaveMorph -= 0.015; //was 0.005
  1049.             }
  1050.             if (WaveMorph > 1.0) WaveMorph = 1.0;
  1051.             if (WaveMorph < 0.0) WaveMorph = 0.0;
  1052.  
  1053.             if(FrameCountWave > 400) {
  1054.             printf("FCW 400\n");
  1055.             FrameCountWave = 0;
  1056.             DestWaveBuffer = 1 - DestWaveBuffer;
  1057. #ifdef __VBCC__
  1058. if (WaveToCalc1 == 1)
  1059. WaveToCalc1 = 5;
  1060. else if (WaveToCalc1 == 2)
  1061. WaveToCalc1 = 7;
  1062. else if (WaveToCalc1 == 3)
  1063. WaveToCalc1 = 11;
  1064. else if (WaveToCalc1 == 4)
  1065. WaveToCalc1 = 1;
  1066. else if (WaveToCalc1 == 5)
  1067. WaveToCalc1 = 2;
  1068. else if (WaveToCalc1 == 7)
  1069. WaveToCalc1 = 3;
  1070. else
  1071. WaveToCalc1 = 4;
  1072.  
  1073. WaveToCalc0 = 0;
  1074.  
  1075.     InitWave(WaveToCalc1, 1);
  1076.     printf("initializing wave %d\n",WaveToCalc1);
  1077.     InitWave(WaveToCalc0, 0);
  1078.  
  1079. #endif
  1080.  
  1081. #ifndef __VBCC__
  1082.                 do {
  1083.                     WaveToCalc = (UBYTE)(rand()>>24) % NUMWAVES;
  1084.                     WaveToCalc = NUMWAVES-1;
  1085.                 } while (WaveToCalc == WaveToCalc0 || WaveToCalc == WaveToCalc1);
  1086.  
  1087.                 if(DestWaveBuffer) {
  1088.                     WaveToCalc1 = WaveToCalc;
  1089.                     InitWave(WaveToCalc1, 1);
  1090.                 }
  1091.                 else {
  1092.                     WaveToCalc0 = WaveToCalc;
  1093.                     InitWave(WaveToCalc0, 0);
  1094.                 }
  1095. #endif
  1096.             }
  1097.  
  1098.             for(i=0; i<Width*2; i++) {
  1099.                 float xf,yf;
  1100.                 ULONG x,y;
  1101.                 xf = (float)WaveX[i]*(1.0-WaveMorph) + (float)WaveX2[i]*(WaveMorph);
  1102.                 yf = (float)WaveY[i]*(1.0-WaveMorph) + (float)WaveY2[i]*(WaveMorph);
  1103.                 x  = (ULONG)xf + Width/2;
  1104.                 y  = (ULONG)yf + Height/2;
  1105.                 if(x < Width-1) {
  1106.                     if(y < Height-1) {
  1107.                         if(x > 0) {
  1108.                             if(y > 0) {
  1109.                                 ActPixel = PixelC + y * Width + x;
  1110.                                 *ActPixel=255;
  1111.                             }
  1112.                         }
  1113.                     }
  1114.                 }
  1115.             }
  1116.  
  1117.             SetAPen(rp, 0);
  1118. /*            if(ShowWave) WritePixelArray(PixelC, 1, Cutoff+1, Width, rp, 0, Cutoff+1, Width-2, Height-2*Cutoff-2, RECTFMT_LUT8);
  1119.             else         WritePixelArray(PixelD, 1, Cutoff+1, Width, rp, 0, Cutoff+1, Width-2, Height-2*Cutoff-2, RECTFMT_LUT8);
  1120.             RectFill(rp, 0, 0, Width, Cutoff);
  1121.             RectFill(rp, 0, Height-Cutoff-1, Width, Height-1);
  1122. */
  1123.             if(ShowWave) WritePixelArray(PixelC, 1, Cutoff+1, Width, rp, Woffset, Cutoff+1, Width-2, Height-2*Cutoff-2, RECTFMT_LUT8);
  1124.             else         WritePixelArray(PixelD, 1, Cutoff+1, Width, rp, Woffset, Cutoff+1, Width-2, Height-2*Cutoff-2, RECTFMT_LUT8);
  1125.             RectFill(rp, 0, 0, Width, Cutoff);
  1126.             RectFill(rp, 0, Height-Cutoff-1, Width, Height-1);
  1127.  
  1128.  
  1129.  
  1130.  
  1131.             if(DisplayFPS)
  1132.             {
  1133.                 Move(rp, 0, 20);
  1134.                 SetABPenDrMd(rp, 255, 0, JAM2);
  1135.                 sprintf(FPStext, "%3ld fps       ", 5*eclock/itime);
  1136.                 Text(rp, FPStext, 7);
  1137.             }
  1138.         }
  1139.     }
  1140. }
  1141.  
  1142.  
  1143.  
  1144. void Blur(UBYTE *PixelC, UBYTE *PixelD) {
  1145.   UBYTE *ActPixel;
  1146.   UBYTE *DstPixel;
  1147.   UBYTE *AbovePixel, *BelowPixel;
  1148.   UBYTE Left, Act, Right;
  1149.   WORD w;
  1150.   ULONG i;
  1151.  
  1152.     PixelC += Width*Cutoff;
  1153.     PixelD += Width*Cutoff;
  1154.  
  1155.   ActPixel   = PixelC+Width+1;
  1156.   AbovePixel = ActPixel-Width;
  1157.   BelowPixel = ActPixel+Width;
  1158.   DstPixel   = PixelD+Width+1;
  1159.  
  1160.   Left  = 0;
  1161.   Act   = 0;
  1162.   Right = 0;
  1163.  
  1164.     for(i=Width*(Cutoff+1); i<(Width*(Height-Cutoff-2)-2); i++) {
  1165.     Right = *(ActPixel+1);
  1166.  
  1167.     w = (Right + Act + Left + *AbovePixel + *BelowPixel) * 3 / 16;
  1168.         if(w<0) w=0;
  1169.     *DstPixel++ = w;
  1170.  
  1171.     ActPixel++;
  1172.     AbovePixel++;
  1173.     BelowPixel++;
  1174.  
  1175.     Left = Act;
  1176.     Act = Right;
  1177.   }
  1178. }
  1179.  
  1180. void ShowRequester(char *Text, char *Button) {
  1181.     struct EasyStruct Req;
  1182.     Req.es_StructSize   = sizeof(struct EasyStruct);
  1183.     Req.es_Flags        = 0;
  1184.   Req.es_Title        = "AmigaAMP Plugin";
  1185.   Req.es_TextFormat   = (UBYTE*)Text;
  1186.   Req.es_GadgetFormat = (UBYTE*)Button;
  1187.     EasyRequestArgs(NULL, &Req, NULL, NULL);
  1188. }
  1189.  
  1190. BOOL OpenTimer(void) {
  1191.     struct EClockVal ev = {0,0};
  1192.  
  1193.     if(TimerMP=(struct MsgPort*)CreatePort(0,0)) {
  1194.         if(TimerIO=(struct timerequest *)CreateIORequest(TimerMP, sizeof(struct timerequest))) {
  1195.             TimerError=OpenDevice("timer.device", UNIT_ECLOCK, (struct IORequest *)TimerIO, 0);
  1196.             if(TimerError==0) {
  1197.  
  1198.                 TimerBase = (struct Library*) &TimerIO->tr_node.io_Device->dd_Library;
  1199.                 EFreq=ReadEClock(&ev);
  1200.  
  1201.                 TimerMask = 1L << TimerMP->mp_SigBit;
  1202.  
  1203.                 return(TRUE);
  1204.             }
  1205.         }
  1206.     }
  1207.     return(FALSE);
  1208. }
  1209.  
  1210. void CloseTimer(void) {
  1211.     if(!TimerError)   CloseDevice((struct IORequest *)TimerIO);
  1212.     if(TimerIO)       DeleteIORequest(TimerIO);
  1213.     if(TimerMP)       DeletePort(TimerMP);
  1214. }
  1215.  
  1216. void StartTimer(void) {
  1217.     TimerIO->tr_node.io_Command = TR_ADDREQUEST;
  1218.     TimerIO->tr_node.io_Flags   = 0;
  1219.     TimerIO->tr_time.tv_secs    = 0;
  1220.     TimerIO->tr_time.tv_micro   = EFreq/LimitFPS;
  1221.     SendIO((struct IORequest *)TimerIO);
  1222. }
  1223.  
  1224. struct MsgPort *MyCreatePort(UBYTE *name, LONG pri) {
  1225.     int sigBit;
  1226.     struct MsgPort *mp;
  1227.  
  1228.     if((sigBit = AllocSignal(-1L)) == -1)    return(NULL);
  1229.  
  1230.     mp = (struct MsgPort*) AllocVec(sizeof(struct MsgPort), MEMF_PUBLIC|MEMF_CLEAR);
  1231.  
  1232.     if(!mp) {
  1233.         FreeSignal(sigBit);
  1234.         return(NULL);
  1235.     }
  1236.  
  1237.     mp->mp_Node.ln_Name = name;
  1238.     mp->mp_Node.ln_Pri  = pri;
  1239.     mp->mp_Node.ln_Type = NT_MSGPORT;
  1240.     mp->mp_Flags        = PA_SIGNAL;
  1241.     mp->mp_SigBit       = sigBit;
  1242.     mp->mp_SigTask      = FindTask(NULL);
  1243.     if(name) AddPort(mp);
  1244.     #if defined (__SASC) || defined (__VBCC__)
  1245.         else NewList(&(mp->mp_MsgList));
  1246.     #else
  1247.         else NewListPPC(&(mp->mp_MsgList));
  1248.     #endif
  1249.  
  1250.     return(mp);
  1251. }
  1252.  
  1253. void MyDeletePort(struct MsgPort *mp) {
  1254.     if(mp->mp_Node.ln_Name) RemPort(mp);
  1255.     mp->mp_SigTask         = (struct Task *) -1;
  1256.     mp->mp_MsgList.lh_Head = (struct Node *) -1;
  1257.     FreeSignal(mp->mp_SigBit);
  1258.     FreeVec(mp); mp=NULL;
  1259. }
  1260.  
  1261. void InitField(LONG *Zoom, ULONG Width, ULONG Height) {
  1262.     LONG i,xs,ys,xd,yd;
  1263.  
  1264.     float scale,greater;
  1265.     float xsf,ysf,xdf,ydf;
  1266.     float rsf,tsf,rdf,tdf;
  1267.     float wf,hf;
  1268.  
  1269.     wf=(float)Width;
  1270.     hf=(float)Height;
  1271.  
  1272.     greater=1.0;
  1273.     if(wf > greater) greater = wf;
  1274.     if(hf > greater) greater = hf;
  1275.  
  1276.     scale = 1.0 / (greater/2.0);
  1277.  
  1278.     for(yd=0; yd<(Height); yd++) {
  1279.         for(xd=0; xd<(Width); xd++) {
  1280.             xdf = (xd - wf/2.0) * scale;
  1281.             ydf = (yd - hf/2.0) * scale;
  1282.  
  1283.             xsf = xdf - xdf * 0.075;
  1284.             ysf = ydf - ydf * 0.075;
  1285.  
  1286.             xs = xsf/scale + wf/2.0;
  1287.             ys = ysf/scale + hf/2.0;
  1288.  
  1289.             if(xs < Width/2)  xs++;
  1290.             if(ys < Height/2) ys++;
  1291.  
  1292.             if(xs < 0)      xs = 0;
  1293.             if(xs > Width)  xs = Width;
  1294.             if(ys < 0)      ys = 0;
  1295.             if(ys > Height) ys = Height;
  1296.  
  1297.             Zoom[Width * yd + xd] = Width * ys + xs;
  1298.         }
  1299.     }
  1300. }
  1301.  
  1302.  
  1303. void MakeCMap(void) {
  1304.     int j,i,c;
  1305.     float r,g,b;
  1306.     float rs,gs,bs;
  1307.  
  1308.     r=255; g=255; b=255;
  1309.  
  1310.     c=255;
  1311.  
  1312.     Colour[0]=256L<<16+0;
  1313.  
  1314.     for(j=0; j<4; j++) {
  1315.         rs = (r - (float)MidR[j]) / 64.0;
  1316.         gs = (g - (float)MidG[j]) / 64.0;
  1317.         bs = (b - (float)MidB[j]) / 64.0;
  1318.         for(i=0; i<64; i++) {
  1319.             Colour[1+3*c+0] = (ULONG)r << 24;
  1320.             Colour[1+3*c+1] = (ULONG)g << 24;
  1321.             Colour[1+3*c+2] = (ULONG)b << 24;
  1322.             r -= rs;
  1323.             g -= gs;
  1324.             b -= bs;
  1325.             c--;
  1326.         }
  1327.     }
  1328.  
  1329. }
  1330.  
  1331. void MakeTitle(void) {
  1332.     long x,y,i,p,s,v,xs,ys;
  1333.     UWORD Blt1[27] = {
  1334.         0x7008,0x0000,0x0000,0x8808,0x0000,0x0000,0x822B,0x1963,
  1335.         0x8E38,0x722C,0xA590,0x5144,0x0A28,0x9913,0xD07C,0x8A28,
  1336.         0x8514,0x5040,0x8A68,0xA594,0xD144,0x71AF,0x1963,0x4E38,
  1337.         0x0000,0x0100,0x0000
  1338.     }; // W=46, H=9
  1339.     UWORD Blt2[54] = {
  1340.         0x8001,0xF400,0x0000,0x0101,0x0000,0x0080,0x8000,0x4400,
  1341.         0x0000,0x0111,0x0000,0x0080,0xB220,0x458E,0x7638,0xC111,
  1342.         0x3967,0x9C80,0xCA20,0x4651,0x4905,0x2092,0x4590,0xA280,
  1343.         0x8940,0x4451,0x493C,0xC0AA,0x7D11,0x3E80,0x8940,0x4451,
  1344.         0x4944,0x20AA,0x4112,0x2080,0x8880,0x4451,0x494D,0x2044,
  1345.         0x4514,0x2280,0xF080,0x444E,0x4934,0xC044,0x3917,0x9C80,
  1346.         0x0100,0x0000,0x0000,0x0000,0x0000,0x0000
  1347.     }; // W=89, H=9
  1348.  
  1349.     xs = (Width-46)/2;
  1350.     ys = Height/2-30-9;
  1351.     s=0;
  1352.     for(y=0; y<9; y++) {
  1353.         x=0;
  1354.         for(i=0; i<3; i++) {
  1355.             for(p=0; p<16; p++) {
  1356.                 x++;
  1357.                 v = Blt1[s] & (1<<(15-p));
  1358.                 if(v) PixelC[(ys+y)*Width+xs+x] = 255;
  1359.             }
  1360.             s++;
  1361.         }
  1362.     }
  1363.     xs = (Width-89)/2;
  1364.     ys = Height/2+30;
  1365.     s=0;
  1366.     for(y=0; y<9; y++) {
  1367.         x=0;
  1368.         for(i=0; i<6; i++) {
  1369.             for(p=0; p<16; p++) {
  1370.                 x++;
  1371.                 v = Blt2[s] & (1<<(15-p));
  1372.                 if(v) PixelC[(ys+y)*Width+xs+x] = 255;
  1373.             }
  1374.             s++;
  1375.         }
  1376.     }
  1377. }
  1378.  
  1379.  
  1380. void ReColor(void) {
  1381. #ifndef __VBCC__
  1382.  
  1383.     int i;
  1384.     for(i=0; i<3; i++) {
  1385.         if(MidR[i] > MidRdst[i]) MidR[i] --;
  1386.         if(MidG[i] > MidGdst[i]) MidG[i] --;
  1387.         if(MidB[i] > MidBdst[i]) MidB[i] --;
  1388.         if(MidR[i] < MidRdst[i]) MidR[i] ++;
  1389.         if(MidG[i] < MidGdst[i]) MidG[i] ++;
  1390.         if(MidB[i] < MidBdst[i]) MidB[i] ++;
  1391.  
  1392.     }
  1393. #endif
  1394.     MakeCMap();
  1395.     LoadRGB32(&PluginScreen->ViewPort, Colour);
  1396. }
  1397.  
  1398. float rnd(float max) {
  1399.     ULONG r;
  1400.     ULONG m;
  1401.  
  1402.     m = (ULONG)(max * 10000.0);
  1403.  
  1404.     r=(rand()>>8) % m;
  1405.  
  1406.     return (float)r/10000.0;
  1407. }
  1408.  
  1409. float sgn(float val) {
  1410.     if(val > 0.0) return  1.0;
  1411.     if(val < 0.0) return -1.0;
  1412.     return 0.0;
  1413. }
  1414.  
  1415. float trnc(float value) {
  1416.     return ceil(value);
  1417. }
  1418.  
  1419. #ifdef __SASC
  1420. void SetPriority(void) {
  1421.     struct TagItem MyTags[2];
  1422.     if(PPCLibBase=OpenLibrary("ppc.library",0)) {
  1423.         MyTags[0].ti_Tag  = PPCTASKTAG_PRIORITY;
  1424.         MyTags[0].ti_Data = 15;
  1425.         MyTags[1].ti_Tag     = TAG_END;
  1426.         CloseLibrary(PPCLibBase);
  1427.     }
  1428. }
  1429. #endif
  1430.  
  1431.  
  1432.  
  1433.  
  1434.  
  1435.  
  1436.